package leetcode.剑指offer.剑指II;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/12/10 20:09
 * @description：https://leetcode-cn.com/problems/VvJkup/
 */
public class 剑指_II_83_没有重复元素集合的全排列 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.permute(new int[]{1, 2, 3}));
    }

    class Solution {
        private List<List<Integer>> ans = new ArrayList<>();
        public List<List<Integer>> permute(int[] nums) {
            List<Integer> list = new ArrayList<>();
            for (int num : nums) {
                list.add(num);
            }
            dfs(list, 0, nums.length);
            return ans;
        }

        private void dfs(List<Integer> list, int i, int length) {
            if (i == length) {
                ans.add(new ArrayList<>(list));
                return;
            }
            for (int j = i; j < length; j++) {
                Collections.swap(list, i, j);
                dfs(list, i + 1, length);
                Collections.swap(list, i, j);
            }

        }
    }
}
